package elitech.vietnam.weatherfashion.widget;

import elitech.vietnam.weatherfashion.R;
import android.content.Context;
import android.util.AttributeSet;
import android.widget.Button;

public class LikeButton extends Button {
	
	private int[] res = null;
	
	public LikeButton(Context context) {
		super(context);
	}

	public LikeButton(Context context, AttributeSet attrs, int defStyle) {
		super(context, attrs, defStyle);
	}

	public LikeButton(Context context, AttributeSet attrs) {
		super(context, attrs);
	}
	
	public void setUp(boolean xSize) {
		if (xSize) 
			res = new int[] {R.drawable.heart_like, R.drawable.heart_liked};
		else 
			res = new int[] {R.drawable.heart1_like, R.drawable.heart1_liked};
		setBackgroundResource(res[0]);
		setText("0");
	}
	
	public void setData(int likes, boolean liked) {
		if (res == null)
			return;
		setText(String.valueOf(likes));
		setBackgroundResource((liked) ? res[1] : res[0]);
	}
	
	@Override
	public void setText(CharSequence text, BufferType type) {
		super.setText(text, type);
		if (getWidth() > getHeight())
			setHeight(getWidth());
		else
			setWidth(getHeight());
	}
}
